const axios = require('axios');
const fs = require("fs");
const path = require("path");

const server = axios.create({
    baseURL: "https://s1.aigei.com/",
    headers:  {
        "accept": "*/*",
        "accept-language": "zh-CN,zh;q=0.9",
        "range": "bytes=0-",
        "sec-ch-ua": "\"Chromium\";v=\"21\", \" Not;A Brand\";v=\"99\"",
        "sec-ch-ua-mobile": "?0",
        "sec-ch-ua-platform": "\"Windows\"",
        "sec-fetch-dest": "audio",
        "sec-fetch-mode": "no-cors",
        "sec-fetch-site": "same-site",
        "cookie": "gei_d_u=9494dfaa60314cacb93864193bb3a566; oOO0OO0oOO00oo0o=true; OooOO000oOOO00o=697c7f1eb338413ca1b80a6c0b861f40; geiweb-v=zZ+S93HA1QfyHPlVpdpzi8+cLdsMc170j5AIvNIoiD2RLuYNUmkEK8jo5WKDQ6dk",
        "Referer": "https://www.aigei.com/",
        "Referrer-Policy": "strict-origin-when-cross-origin"
    },
});




//https://s1.aigei.com/src/aud/mp3/bf/bf86da9a82f24b66a8f83648affc0614.mp3?e=1699459740&token=P7S2Xpzfz11vAkASLTkfHN7Fw-oOZBecqeJaxypL:ssCgGq12RsGYEBpJlbEurY4e2As=
let req = () => {

    server.get("src/aud/mp3/bf/bf86da9a82f24b66a8f83648affc0614.mp3?e=1699459740&token=P7S2Xpzfz11vAkASLTkfHN7Fw-oOZBecqeJaxypL:ssCgGq12RsGYEBpJlbEurY4e2As=", {
        responseType: 'arraybuffer'
    }).then(res=>{
        saveJson("./download/xxx.mp3",res.data)
    })


}
let saveJson = (pathStr, data) => {

    let parts = pathStr.split('/');
    let parentPath = parts.slice(0, 2).join('/');

    if (!fs.existsSync(parentPath)) {
        fs.mkdirSync(parentPath, {recursive: true});
    }

    const filePath = path.join(parentPath, parts.slice(2,parts.length).join('/')
        .replaceAll("\""," ")
        .replaceAll("/"," ")
        .replaceAll(";"," ")

    ); // 构建文件路径

    // fs.writeFileSync(filePath, JSON.stringify(data), 'utf-8');
    fs.writeFileSync(filePath,  (data), 'utf-8');
}

req()